#ifndef INDEXATOR_H
#define INDEXATOR_H

//Thread pool for perfoming asynchronous queries without result

#include <vector>

#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>

#include "pgquery.h"

namespace Porridge
{

class Indexator
{
public:
    Indexator();
    ~Indexator();

    void operator ()(const std::string & tableName);

    void setConnectionInfo(const std::string & connInfo) {m_connectionInfo = connInfo;}
    void setQueryThreadLimit(size_t limit = 0);
    template<typename InputIterator>
    void setProcessingQueries(InputIterator first, InputIterator last)
    { m_processingQueries.assign(first, last);}
    void appendProcessingQuery(const std::string &query){m_processingQueries.push_back(query);}

private:
    Indexator(const Indexator&);
    Indexator& operator =(const Indexator&);

    void doWork(const std::string &);

    PGQueryQueue m_PGQueryQueue;
    std::vector<boost::shared_ptr<PGQuery> > m_PGQueryVector;
    boost::thread_group m_ThreadGroup;
    size_t m_queryThreadCount;
    size_t m_queryThreadLimit;
    std::string m_connectionInfo;
    std::vector<std::string> m_processingQueries;
};

}//namespace Porridge

#endif // INDEXATOR_H
